#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "imageprocessing/ImageProcessor.h"

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;

    // 创建并注册图像处理器
    ImageProcessor imageProcessor;
    engine.rootContext()->setContextProperty("imageProcessor", &imageProcessor);

    // 创建并注册图像提供者
    EdgeDetectionProvider edgeProvider(&imageProcessor);
    engine.addImageProvider("edgedetection", &edgeProvider);

    const QUrl url(QStringLiteral("qrc:/AppDemo/main.qml"));
    qDebug() << "Loading QML from:" << url;
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl)
                     {
        if (!obj && url == objUrl) {
            qCritical() << "Failed to load QML from:" << url;
            QCoreApplication::exit(-1);
        } else {
            qDebug() << "Successfully loaded QML from:" << url;
        } }, Qt::QueuedConnection);
    engine.load(url);
    qDebug() << "QML loading completed";

    return app.exec();
}
